package com.ruoyi.project.bas.basCustomer.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.project.bas.basCustomer.domain.BasCustomer;
import com.ruoyi.project.bas.basCustomer.service.IBasCustomerService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 客户信息Controller
 * 
 * @author qxq
 * @date 2023-05-31
 */
@Controller
@RequestMapping("/bas/basCustomer")
public class BasCustomerController extends BaseController
{
    private String prefix = "bas/basCustomer";

    @Autowired
    private IBasCustomerService basCustomerService;

    @GetMapping()
    public String basCustomer()
    {
        return prefix + "/basCustomer";
    }

    /**
     * 查询客户信息列表
     */
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(BasCustomer basCustomer)
    {
        startPage();
        List<BasCustomer> list = basCustomerService.selectBasCustomerList(basCustomer);
        return getDataTable(list);
    }

    /**
     * 导出客户信息列表
     */
    @Log(title = "客户信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(BasCustomer basCustomer)
    {
        List<BasCustomer> list = basCustomerService.selectBasCustomerList(basCustomer);
        ExcelUtil<BasCustomer> util = new ExcelUtil<BasCustomer>(BasCustomer.class);
        return util.exportExcel(list, "客户信息数据");
    }

    /**
     * 新增客户信息
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存客户信息
     */
    @Log(title = "客户信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(BasCustomer basCustomer)
    {
        return toAjax(basCustomerService.insertBasCustomer(basCustomer));
    }

    /**
     * 修改客户信息
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap)
    {
        BasCustomer basCustomer = basCustomerService.selectBasCustomerById(id);
        mmap.put("basCustomer", basCustomer);
        return prefix + "/edit";
    }

    /**
     * 修改保存客户信息
     */
    @Log(title = "客户信息", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(BasCustomer basCustomer)
    {
        return toAjax(basCustomerService.updateBasCustomer(basCustomer));
    }

    /**
     * 删除客户信息
     */
    @Log(title = "客户信息", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(basCustomerService.deleteBasCustomerByIds(ids));
    }
}
